package com.Maykk.Demo11;

import java.util.ArrayList;
import java.util.function.Predicate;

/**
 * @ClassName: Demo02
 * @Description: TODO Predicate 判断接口
 * @Author: MaykkStar@163.com
 */
public class PredicateDemo {
    public static void main(String[] args) {
        String[] arr = {"黄固,28", "欧阳锋,43", "段智兴,35", "洪七公,42", "王重阳,43"};
        ArrayList<String> list = runPredicate(arr,
                s -> s.split(",")[0].length() == 3,
                s -> new Integer(s.split(",")[1]) > 40
        );
        System.out.println(list);
    }

    public static ArrayList<String> runPredicate(String[] arr, Predicate<String> p01, Predicate<String> p02) {
        ArrayList<String> list = new ArrayList<>();
        for (String s : arr) {
            if (p01.and(p02).test(s)) list.add(s);
        }
        return list;
    }
}
